package linklist;

public class L24 {
    public ListNode swapPairs(ListNode head) {
        ListNode dumyhead = new ListNode(0);
        dumyhead.next=head;
        ListNode curr=dumyhead;
        ListNode temp;//用于保存两个节点后面的节点
        ListNode fisrtNode;//用于保存两个节点的第一个节点
        ListNode seconNode;//用于保存第二个节点
        while (curr.next!=null && curr.next.next!=null){
            temp=curr.next.next.next;
            fisrtNode=curr.next;
            seconNode=curr.next.next;
            curr.next=seconNode;
            seconNode.next=fisrtNode;
            fisrtNode.next=temp;
            curr=fisrtNode;

        }
        return dumyhead.next;


    }
}
